package com.btl.service.ai.support.rag.generation.knowledge.strategy;

import com.btl.service.ai.support.rag.generation.knowledge.KnowledgeService;
import com.btl.service.ai.support.rag.generation.GenerationModelEnum;
import com.btl.service.ai.support.rag.generation.knowledge.GenerationKnowledgeStrategy;
import dev.langchain4j.model.TokenCountEstimator;
import dev.langchain4j.model.chat.ChatModel;
import dev.langchain4j.rag.content.Content;
import dev.langchain4j.rag.query.Query;
import dev.langchain4j.service.Result;
import dev.langchain4j.store.memory.chat.ChatMemoryStore;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class GenerationKnowledgeOpenAiStrategy extends GenerationKnowledgeStrategy {

    private final TokenCountEstimator huggingFaceTokenCountEstimator;

    private final ChatModel iOpenAiChatModel;

    private final ChatMemoryStore redisChatMemoryStore;

    public GenerationKnowledgeOpenAiStrategy(TokenCountEstimator huggingFaceTokenCountEstimator, ChatModel iOpenAiChatModel, ChatMemoryStore redisChatMemoryStore) {
        this.huggingFaceTokenCountEstimator = huggingFaceTokenCountEstimator;
        this.iOpenAiChatModel = iOpenAiChatModel;
        this.redisChatMemoryStore = redisChatMemoryStore;
    }

    @Override
    public Result<String> generate(Long memoryId, List<Content> contents, Query query) {
        KnowledgeService knowledgeService = buildAiService(iOpenAiChatModel, redisChatMemoryStore, huggingFaceTokenCountEstimator);
        return this.generate(knowledgeService, memoryId, contents, query);
    }


    @Override
    public GenerationModelEnum model() {
        return GenerationModelEnum.OPEN_AI_CHAT_MODEL;
    }
}
